home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 September / Macworld (1998-09).dmg / Shareware World / Info / For Developers / MacZoop 1.8.3 / More Classes / File Classes / ZFolderScanner.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-06  |  3.1 KB  |  138 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            MacZoop - "the framework for the rest of us"         
  5. *
  6. *
  7. *
  8. *            ZFolderScanner.h    -- a generic object for recursively searching folders
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21.  
  22. #pragma once
  23.  
  24. #ifndef __ZFOLDERSCANNER__
  25. #define    __ZFOLDERSCANNER__
  26.  
  27. #ifndef __ZFILE__
  28. #include    "ZFile.h"
  29. #endif
  30.  
  31. class    ZProgress;
  32.  
  33.  
  34. enum
  35. {
  36.     CLASS_ZFolderScanner    = 'zfsc'
  37. };
  38.  
  39.  
  40. class    ZFolderScanner : public ZFile
  41. {
  42. protected:
  43.     short        curDepth;    
  44.     short        searchDepth;
  45.     long        topDirID;
  46.     Boolean        useProgressDialog;
  47.     ZProgress*    itsPD;
  48.     CInfoPBRec     pb;
  49.     Str31        fName;
  50.  
  51. public:    
  52.     ZFolderScanner( const FSSpec& rootFolder );
  53.     ZFolderScanner();
  54.     
  55.     ~ZFolderScanner();
  56.     
  57.     virtual void    SetSearchDepth( const short aSearchDepth );
  58.     virtual Boolean    PickFolder();
  59.     virtual void    ScanFolder();
  60.     
  61.     inline     void    SetUseProgress( Boolean useIt ) { useProgressDialog = useIt; };
  62.     
  63. protected:
  64.     virtual void    Scan1Folder( const long dirID );
  65.     virtual void    Process1File( const FSSpec& aSpec, const OSType fType );
  66.     virtual void    Process1Folder( const FSSpec& aSpec );
  67. };
  68.  
  69. // messages this transmits to its listeners...
  70.  
  71. enum
  72. {
  73.     msgFolderscanProcess1File = 'fscf',
  74.     msgFolderscanProcess1Folder = 'fscd'
  75. };
  76.  
  77. // pass these to SetSearchDepth:
  78.  
  79. enum
  80. {
  81.     kScanEveryFolderInHierarchy    = -1,
  82.     kScanRootFolderOnly = 1
  83. };
  84.  
  85. // structure used for selecting directories in picker
  86.  
  87. typedef struct
  88. {
  89.     StandardFileReply    aReply;
  90.     Boolean                selectHit;
  91.     Boolean                dirFlag;
  92. }
  93. tFolderInfo;
  94.  
  95. // file manager enhancements:
  96.  
  97. Boolean                    ChooseFolder(FSSpec* folderSpec);
  98. static pascal Boolean    GetDirFileFilter(ParmBlkPtr pb, tFolderInfo* fInfo);
  99. static pascal short        GetDirDlgHook(short item, DialogPtr theDialog, tFolderInfo* fInfo);
  100. static void                SetSFButtonTitle(ControlHandle theButton, FSSpec* theFile, Rect* buttonRect);
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.                      
  109.  
  110. /*
  111.  
  112. This object is useful for doing general recursive searches through a hierarchy of folders. For
  113. each file it encounters, it calls Process1File with the file spec. You can override this
  114. method to do whatever you want with the file. If another folder is encountered, it calls
  115. Scan1Folder recursively to the maximum depth you set with SetSearchDepth(). By default this is
  116. 0, so it only searches the first folder. Pass -1 to search all folders below the first folder
  117. as well. If you want to search the entire hard disk, pass the FSSpec of the hard disk in the
  118. constructor, or use the default constructor to search the startup disk.
  119.  
  120. To kick off a search, simply call ScanFolder().
  121.  
  122. To provide a user-interface for selecting a folder, call PickFolder(). This presents a custom
  123. Standard File dialog to pick a folder, which then becomes the current folder. You can then call
  124. ScanFolder to search it.
  125.  
  126. Sincethis inherits from ZFile, you can call GetFSSpec, etc. However, it is meaningless to try to
  127. call Open, etc. on this object, since the spec should be for a folder.
  128.  
  129. */
  130.  
  131.  
  132.  
  133. #define        kDefaultSearchDepth            0
  134. #define        kPickFolderDialogID            8001
  135. #define        kPickFolderButton            13
  136. #define        kStdButtonTextStrID            128
  137.  
  138. #endif